<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>员工信息管理系统 - 员工列表</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
<body>
<header>
    <div class="logo">员工信息管理系统</div>
    <nav>
        <ul>
            <li><a href="../dashboard.jsp">仪表盘</a></li>
            <li class="active"><a href="list.jsp">员工管理</a></li>
        </ul>
    </nav>
    <div class="user-info">
        <span>欢迎, ${user.username}</span>
        <a href="../LogoutServlet" class="logout-btn">退出</a>
    </div>
</header>

<main>
    <div class="content-container">
        <div class="content-header">
            <h2>员工列表</h2>
            <a href="../EmployeeServlet?action=add" class="btn primary">添加新员工</a>
        </div>

        <!-- 搜索表单 -->
        <div class="search-form">
            <form action="../EmployeeServlet?action=search" method="get">
                <div class="form-row">
                    <div class="form-group">
                        <label for="name">员工姓名:</label>
                        <input type="text" id="name" name="name" value="${param.name}">
                    </div>
                    <div class="form-group">
                        <label for="department">部门:</label>
                        <input type="text" id="department" name="department" value="${param.department}">
                    </div>
                    <div class="form-group">
                        <label for="position">职位:</label>
                        <input type="text" id="position" name="position" value="${param.position}">
                    </div>
                    <div class="form-group">
                        <button type="submit" class="btn">搜索</button>
                        <a href="../EmployeeServlet?action=list" class="btn secondary">重置</a>
                    </div>
                </div>
            </form>
        </div>

        <!-- 员工表格 -->
        <div class="table-container">
            <table>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>部门</th>
                    <th>职位</th>
                    <th>薪资</th>
                    <th>入职日期</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="emp" items="${employees}">
                    <tr>
                        <td>${emp.id}</td>
                        <td>${emp.name}</td>
                        <td>${emp.department}</td>
                        <td>${emp.position}</td>
                        <td><fmt:formatNumber value="${emp.salary}" type="number" pattern="###,##0.00"/></td>
                        <td><fmt:formatDate value="${emp.hireDate}" pattern="yyyy-MM-dd"/></td>
                        <td class="actions">
                            <a href="../EmployeeServlet?action=view&id=${emp.id}" class="btn small">查看</a>
                            <a href="../EmployeeServlet?action=edit&id=${emp.id}" class="btn small secondary">编辑</a>
                            <a href="../EmployeeServlet?action=delete&id=${emp.id}" class="btn small danger"
                               onclick="return confirm('确定要删除该员工吗?')">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                <c:if test="${empty employees}">
                    <tr>
                        <td colspan="7" class="no-data">没有找到员工数据</td>
                    </tr>
                </c:if>
                </tbody>
            </table>
        </div>
    </div>
</main>

<footer>
    <p>&copy; 2023 员工信息管理系统</p>
</footer>
</body>
</html>